package de.koller.oceanFramework.glyph;

import de.koller.oceanFramework.tree.Mother;
import de.koller.oceanFramework.tree.Sea3X;

public class GlyphRendererGL extends Sea3X {
	
	@Mother private GlyphScreenGL screen;
	
	private int currentFontColor = 0;
	private int currentBackColor = 0;
	private int currentSecColor = 0xff808080;
	
	private final IFontValue fontValue;

	public GlyphRendererGL( IFontValue fontValue ) {
		this.fontValue = fontValue;
	}

	public void renderString( int x, int y, String text ) {
		for( int i = 0; i < text.length(); i++ )
			renderChar( x+i, y, text.substring( i, i+1 ) );
	}

	public void renderChar( int x, int y, String c ) {
		int[] ck = fontValue.getGlyphP( c );
		Glyph g = new Glyph( currentFontColor, currentBackColor, ck[0], ck[1] );
		g.setSecondaryColor( currentSecColor );
		screen.renderGlyph( x, y, g );
	}
	
	public void renderGlyph( int x, int y, int cx, int cy ) {
		Glyph g = new Glyph( currentFontColor, currentBackColor, cx, cy );
		g.setSecondaryColor( currentSecColor );
		screen.renderGlyph( x, y, g );
	}
	
	public void setCurrentBackColor( int currentBackColor ) {
		this.currentBackColor = currentBackColor;
	}

	public void setCurrentFontColor( int currentFontColor ) {
		this.currentFontColor = currentFontColor;
	}

	public void setCurrentSecColor( int currentSecColor ) {
		this.currentSecColor = currentSecColor;
	}

	public int[] getGlyphPos( int screenX, int screenY ) {
		return new int[] {	screenX / GlyphScreen.GLYPH_WIDTH,
							screenY / GlyphScreen.GLYPH_HEIGHT };
	}
}
